package com.jadefashion.controller;

import com.jadefashion.health.entity.Result;
import com.jadefashion.health.resources.MessageConstant;
import com.jadefashion.service.ReportService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("report")
public class ReportController {
    @Reference
    ReportService reportService;

    @RequestMapping("setmealRate.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object setmealRate() {
        Result result = null;
        try {
            List<Map> list = reportService.findOrderNumber();
            result = new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, list);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
        return result;
    }

    @RequestMapping("getMemberReport1.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object getMemberReport() {
        Result result = null;
        try {
            Map map = reportService.getMemberReport();
            result = new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, map);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
        return result;
    }

    @RequestMapping("findBusinessData.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object findBusinessData() {
        Result result = null;
        try {
            Map map = reportService.findBusinessData();
            result = new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, map);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
        return result;
    }

    /**
     * 前台传送时间过来,根据时间展示会员数据
     * @return
     */
    @RequestMapping("getMemberReport.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object getMemberReport(@RequestBody Map time){
        Result result= null;
        try {
            Map map=reportService.getMemberReport(time);
            result = new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS,map);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS);
        }
        return result;
    }

    @RequestMapping("setmemberAge.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object setmemberAge() {
        Result result = null;
        try {
            List<Map> list = reportService.setmemberAge();
            result = new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, list);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
        return result;
    }

    @RequestMapping("getSexNum.do")
    @PreAuthorize("hasAuthority('REPORT_VIEW')")
    public Object getSexNum() {
        Result result = null;
        try {
            List<Map> list = reportService.getSexNum();
            result = new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, list);
        } catch (Exception e) {
            result = new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
        return result;
    }




}
